package com.ourteam.product.model.api;

import com.ourteam.product.model.dao.ProductModelObjectDAOQueryBean;
import com.ourteam.product.model.domain.ProductModelObjectBean;
import com.ourteam.product.model.domain.ProductModelPackageBean;
import com.ourteam.product.model.service.IProductModelService;
import com.ourteam.product.model.service.ProductModelServiceFactory;

public class ProductModelPackageHelper {
	
	static final IProductModelService PRODUCT_MODEL_SERVICE = ProductModelServiceFactory.getProductModelService();


	private ProductModelPackageBean modelPackageBean;

	public ProductModelPackageHelper(ProductModelPackageBean modelPackageBean) {
		super();
		this.modelPackageBean = modelPackageBean;
	}

	public String getPackageName() {
		return modelPackageBean.getPackageName();
	}

	public String getDomainName() {
		return modelPackageBean.getDomainName();
	}

	public ProductModelObjectHelper[] getModelObjects() throws Exception {

		ProductModelObjectDAOQueryBean queryBean = new ProductModelObjectDAOQueryBean();

		queryBean.createCriteria()
				.andPackageIdEqualTo(modelPackageBean.getId());

		ProductModelObjectBean[] modelObjectBeans = PRODUCT_MODEL_SERVICE
				.queryProductModelObjects(queryBean);

		ProductModelObjectHelper[] modelObjectHelpers = new ProductModelObjectHelper[modelObjectBeans.length];

		for (int i = 0; i < modelObjectHelpers.length; i++) {
			modelObjectHelpers[i] = new ProductModelObjectHelper(
					modelObjectBeans[i]);
		}

		return modelObjectHelpers;
	}
}
